package com.lyc.user.util;

import java.sql.*;

public class jdbcUtil {
 private final static  String USERNAME="root";
 private final static String PASSWORD="root";
 private final static String URL="jdbc:mysql://localhost:3306/user";
 private final static String DRIVER="com.mysql.jdbc.Driver";
 static {
//	 Properties pro=new  Properties();
//	 try {
//
// 	pro.load(jdbcUtil.class.getClassLoader().getResourceAsStream("jdbc.properties"));
//	} catch (IOException e) {
//		e.printStackTrace();
//	}
	 
//	 USERNAME=pro.getProperty("mysql.username");
//	 PASSWORD=pro.getProperty("mysql.password");
//	 URL=pro.getProperty("mysql.url");
//	 DRIVER=pro.getProperty("mysql.driver");
//
	 try {
		Class.forName(DRIVER);
	} catch (ClassNotFoundException e) {
		e.printStackTrace();
	}
 }
 
 public static Connection getConnection() {
	 Connection connection=null;
	 try {
		 connection=DriverManager.getConnection(URL, USERNAME, PASSWORD);
	} catch (SQLException e) {
		e.printStackTrace();
	}
	 
	return connection;
 }
 public static void close(ResultSet resultSet,Statement statement,Connection connection) {
	 if (resultSet!=null) {
		try {
			resultSet.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	 if (statement!=null) {
		try {
			statement.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	 if (connection!=null) {
		try {
			connection.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
 }
 
}
